def update_class(cls, attrs):
    for name,value in attrs.items():
        if name not in ('__class__', '__bases__', '__metaclass__',
        '__module__'):
            if hasattr(cls, name):
                setattr(cls, 'old_'+name, getattr(cls, name))
            setattr(cls, name, value)
    return cls

def update_metaclass(name, bases, attrs):
    try:
        import sys
        exist_class=getattr(sys.modules[attrs['__module__']], name)
        return update_class(exist_class, attrs)
    except AttributeError:
        print 'debug: not find class',name
        return type(name, (object,), attrs)

if __name__ == '__main__':
    # test
    class Temp(object):
        def virtual(self):
            return 1
    t = Temp()
    class Temp(object):
        __metaclass__ = update_metaclass
        def __init__(self, a):
            self.a = a
        def get_a(self):
            return self.a
        def virtual(self):
            return 2
    assert hasattr(t, 'get_a')
    assert hasattr(t, 'virtual_old')
